package com.video.netty.InChannelHandler;

import com.alibaba.fastjson.JSONObject;
import com.video.entity.ClientMsg;
import com.video.service.client.IClientService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * 终端下线处理Handler
 *
 * {"id":"offline","response":"1"}
 */
@BaseChannelHandler.MsgHandler
public class WsOfflineChannelHandler extends BaseChannelHandler {

    @Autowired
    private IClientService clientService;

    @Override
    protected String msgId() {
        return "offline";
    }

    @Override
    protected void msgHandler(JSONObject json) {

        int userid = json.getIntValue("response");
        ClientMsg clientMsgOff = clientService.getById(userid);
        clientMsgOff.setId("offline");
        clientMsgOff.setStatus(0);
        clientService.insertOrUpdate(clientMsgOff);

    }

}
